﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using Wys.DataForm.CSharp.SoftWare;

namespace Wys.DataForm.CSharp
{
    public partial class SoftWareListUpdate : Wys.Control.Vb.AutoAdjustFrom
    {
        public String strCurrentId = String.Empty;

        //A-2009-09-11
        public int iListToUpdate = -1;
        private String strSql = String.Empty;
        private String strSql1 = String.Empty;
        //A-2009-09-11

        //A-2010-02-21
        private bool _软件图标 = false;
        private bool _软件大小 = false;
        //A-2010-02-21

        #region 构造函数
        public SoftWareListUpdate()
        {
            InitializeComponent();
        }
        #endregion       

        #region 初始化下拉框
        public void LoadInitData()
        {          

        }
        #endregion

        #region 填充网格控件
        public void LoadData()
        {
            //A-2009-10-11
            if (GetAppSettingConfig("BrowserOtherUserData") != "1")
            {
                this.lstView.UserNameValue = this.strName;
                this.lstView.UserName = "USERNAME";
                this.lstView.BrowserData = false;
            }
            else
            {
                this.lstView.UserNameValue = this.strName;
                this.lstView.UserName = "USERNAME";
                this.lstView.BrowserData = false;
            }
            //A-2009-10-11
            try
            {
                 //A-2009-09-11
                if (iListToUpdate > -1)
                {
                    this.lstView.SetRsSQLITE(this.strSql, this.strSql1, ct, 1);
                    this.btnAdd.Enabled = false;
                    this.cboSoftWareType.Enabled = false;
                }
                else
                {
                    String strSql11 = "select ID,Title              from XscSoftWare Where 1=1 ";
                    String strSql12 = "select count(*) as PageCount from XscSoftWare Where 1=1 ";
                    lstView.SetRsSQLITE(strSql11, strSql12, ct, 1);
                }
                //A-2009-09-11

                //D-2009-09-11
                //String strSql11 = "select ID,Title from XscSoftWare ";
                //String strSql12 = "select count(*) as PageCount from XscSoftWare ";
                //lstView.SetRsSQLITE(strSql11, strSql12, ct, 1);
                //D-2009-09-11
            }
            catch (Exception ee)
            {
                //SaveException(ee);//D-2009-10-11
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ee, MethodBase.GetCurrentMethod().GetType());//A-2009-10-11 
            }

        }
        #endregion

        #region 根据选择填充网格控件
        //private void cboSoftWareType_ItemChanged(string strText)
        //{
        //     //A-2009-09-11
        //    if (iListToUpdate > -1)
        //    {
        //        this.lstView.SetRsSQLITE(this.strSql, this.strSql1, ct, 1);
        //        this.btnAdd.Enabled = false;
        //        this.cboSoftWareType.Enabled = false;
        //    }
        //    else
        //    {
        //        String strSql1 = "";
        //        String strSql12 = "";
        //        if (strText.ToUpper() == "ALL")
        //        {
        //            strSql1 = "select ID,Title from XscSoftWare ";
        //            strSql12 = "select count(*) as PageCount from XscSoftWare ";
        //        }
        //        else
        //        {
        //            strSql1 = "select ID,Title from XscSoftWare Where SoftWare='" + strText + "'";
        //            strSql12 = "select count(*) as PageCount from XscSoftWare Where SoftWare='" + strText + "'";
        //        }
        //        lstView.SetRsSQLITE(strSql1, strSql12, ct, 1);
        //    }
        //    //A-2009-09-11
        //    //D-2009-09-11
        //    //String strSql1 = "";
        //    //String strSql12 = "";
        //    //if (strText.ToUpper() == "ALL")
        //    //{
        //    //    strSql1 = "select ID,Title from XscSoftWare ";
        //    //    strSql12 = "select count(*) as PageCount from XscSoftWare ";
        //    //}
        //    //else
        //    //{
        //    //    strSql1 = "select ID,Title from XscSoftWare Where SoftWare='" + strText + "'";
        //    //    strSql12 = "select count(*) as PageCount from XscSoftWare Where SoftWare='" + strText + "'";
        //    //}
        //    //lstView.SetRsSQLITE(strSql1, strSql12, ct, 1);
        //    //D-2009-09-11

        //}
        #endregion

        #region 填充明细部
        private void lstView_ItemClickRefreshData(string strId, ref bool bState)
        {
            try
            {
                //A-2009-10-11
                this.btnUpdate.Enabled = false;
                this.btnDel.Enabled = false;
                this.btnSelectType1.Enabled = false;
                this.btnSelect.Enabled = false;
                //A-2009-10-11
                //查询数据
                this.strCurrentId = strId;
                String strSql = " select *  from XscSoftWare ";              
                strSql += "       where XscSoftWare.Id='" + strId + "'";
                ADODB.Recordset rs = ct.GetTable(strSql);
                if (rs != null)
                {
                    if (rs.EOF == false)
                    {
                        cUtil.RefreshTitle(su, rs.Fields["USERNAME"].Value + "", rs.Fields["AddTime"].Value + "", rs.Fields["OPTIME"].Value + "", strId);
                        //A-2009-10-10
                        if ((rs.Fields["USERNAME"].Value + "").ToString() != this.strName)
                        {
                            this.btnUpdate.Enabled = false;
                            this.btnDel.Enabled = false;
                            this.btnSelectType1.Enabled = false;
                            this.btnSelect.Enabled = false;
                        }
                        else
                        {
                            this.btnDel.Enabled = true;
                            this.btnUpdate.Enabled = true;
                            this.btnSelectType1.Enabled = true;
                            this.btnSelect.Enabled = true;
                        }
                        //A-2009-10-10
                        strCurrentId = rs.Fields["Id"].Value.ToString();
                        this.txtTitle.Text = rs.Fields["Title"].Value.ToString();
                        //生成一个完整的路径  
                        this.cboSoftWareType1.Tag = rs.Fields["type1"].Value.ToString();
                        this.cboSoftWareType1.Text = ct.GetParentName(cboSoftWareType1.Tag.ToString(), "XscBugType", "Name", "ParentID", "ID");

                        this.cboSoftWareType2.Tag = rs.Fields["type2"].Value.ToString();
                        this.cboSoftWareType2.Text = ct.GetParentName(cboSoftWareType2.Tag.ToString(), "XscBugType", "Name", "ParentID", "ID");

                        this.cboSoftWareType3.Tag = rs.Fields["type3"].Value.ToString();
                        this.cboSoftWareType3.Text = ct.GetParentName(cboSoftWareType3.Tag.ToString(), "XscBugType", "Name", "ParentID", "ID");

                        this.cboSoftWareType4.Tag = rs.Fields["type4"].Value.ToString();
                        this.cboSoftWareType4.Text = ct.GetParentName(cboSoftWareType4.Tag.ToString(), "XscBugType", "Name", "ParentID", "ID");

                        this.cboSoftWareType5.Tag = rs.Fields["type5"].Value.ToString();
                        this.cboSoftWareType5.Text = ct.GetParentName(cboSoftWareType5.Tag.ToString(), "XscBugType", "Name", "ParentID", "ID");

                        this.txtPath.Text = GetFilePath("", rs.Fields["FileName"].Value.ToString());
                        this.txtMemo.Text = rs.Fields["Memo"].Value.ToString();
                        //A-2009-08-30
                        if (rs.Fields["IsSingleFile"].Value.ToString() == "0")
                        {
                            radFile.Checked = true;
                            radFolder.Checked = false;
                            RefreshEBook(this.txtPath.Text, "0");
                        }
                        else
                        {
                            radFile.Checked = false;
                            radFolder.Checked = true;
                            RefreshEBook(this.txtPath.Text, "1");
                        }
                        //A-2009-08-30
                        rs.Close();
                    }
                    else
                    {
                        this.txtTitle.Text = "";
                        this.txtPath.Text = "";
                        strCurrentId = "";
                    }
                }
                rs = null;
            }
            catch (Exception me)
            {
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());//A-2009-10-11 
            }            
        }
        #endregion     

        #region 窗体初始化事件
        private void SoftWareListUpdate_Load(object sender, EventArgs e)
        {
            if (GetAppSettingConfig("ShowStausBar") == "1")
            {
                if (su == null)
                {
                    cUtil.CreateStausStrip(this, ref su, ref sup);
                }
            }

            ////A-2010-02-21
            //using (Wys.DataForm.CSharp.SoftwareOption so = new Wys.DataForm.CSharp.SoftwareOption())
            //{
            //    so.ShowDialog();
            //    _软件图标 = so.软件图标;
            //    _软件大小 = so.软件大小;
            //}
            ////this.Visible = true;
            ////A-2010-02-21          

            _软件图标 = true;
            //A-2009-10-11
            if (GetAppSettingConfig("BrowserOtherUserData") != "1")
            {
                this.lstView.UserNameValue = this.strName;
                this.lstView.UserName = "USERNAME";
                this.lstView.BrowserData = false;
            }
            else
            {
                this.lstView.UserNameValue = this.strName;
                this.lstView.UserName = "USERNAME";
                this.lstView.BrowserData = false;
            }
            //A-2009-10-11

            LoadInitData();            
            LoadData();

            if (iListToUpdate>-1)
            {
                btnSelectType.Enabled = false;
            }else
            {                   
                //LoadDBToForm();
                this.RefreshData();
            }
            //this.bSaveData = true;
            //StructSaveData sd = new StructSaveData();
            //sd.strControlName = "cboSoftWareType";
            //this.arList.Add(sd);
            //LoadDBToForm();
        }

        #endregion

        #region 删除控件
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (strCurrentId == string.Empty)
            {
                ShowMessageBox("请选择记录");
                return;
            }
            if (ShowMessageResult("是否删除本条记录") == DialogResult.No)
            {
                return;
            }
            //删除对应的文件
            
            DeleteFile(GetCurrentRs(strCurrentId));
            //
            String strSql = "delete from XscSoftWare where id='" + strCurrentId+"'";
            ADODB.Command cmd = new ADODB.Command();
            cmd.CommandText = strSql;
            if (ct.ExcCommand(cmd))
            {
                //添加删除记录功能  A-2010-03-24
                ct.AddDeleteDetal("XscSoftWare", new String[] { "id", "", "" }, new String[] { strCurrentId, "", "", "" }, this.strName);
                //添加删除记录功能  A-2010-03-24
                ShowMessageBox("删除成功");
                //cboSoftWareType_ItemChanged(this.cboSoftWareType.Text);                
            }           
            strCurrentId = "";
            if (iListToUpdate > -1)
            {
                this.Close();
            }
            this.RefreshData();
        }
        //删除对应的记录
        private void DeleteFile(ADODB.Recordset rs)
        {
            if (rs != null)
            {
                if (!rs.EOF)
                {
                    String strPath = GetFilePath("", rs.Fields["FileName"].Value.ToString());
                    if (System.IO.File.Exists(strPath))
                    {
                        try
                        {
                            //避免删除隐藏文件，只读文件报错 D-2010-03-01
                            FileInfo fi = new FileInfo(strPath);                            
                            //fi.Attributes = FileAttributes.Normal; //避免删除隐藏文件，只读文件报错 A-2010-03-01
                            //删除文件 2009-08-10
                            //File.Delete(strPath);
                            //删除目录 2009-08-10
                            //Directory.Delete(fi.Directory.FullName, true); 
                            //避免删除隐藏文件，只读文件报错 D-2010-03-01

                            //避免删除隐藏文件，只读文件报错 A-2010-03-01
                            System.IO.DirectoryInfo dif = new DirectoryInfo(fi.Directory.FullName);
                            fi = null;
                            foreach (System.IO.FileInfo ftemp in dif.GetFiles("*.*", SearchOption.AllDirectories))
                            {
                                ftemp.Attributes = FileAttributes.Normal;
                            }                           
                            dif.Delete(true);
                            //避免删除隐藏文件，只读文件报错 A-2010-03-01
                        }
                        catch (Exception MyE)
                        {
                            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, MyE, MethodBase.GetCurrentMethod().GetType());
                        }                        
                    }
                    rs.Close();
                }
                rs = null;
            }
        }
        #endregion

        #region 更新按钮代码
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(strCurrentId))
            {
                ShowMessageBox("请选择记录");
                return;
            }
            //先做CHECK
            if (String.IsNullOrEmpty(this.txtTitle.Text))
            {
                ShowMessageBox("标题不能为空");
                this.txtTitle.Focus();
                return;
            }
            //
            if (String.IsNullOrEmpty(this.cboSoftWareType1.Text) && String.IsNullOrEmpty(this.cboSoftWareType2.Text) && String.IsNullOrEmpty(this.cboSoftWareType3.Text) && String.IsNullOrEmpty(this.cboSoftWareType4.Text) && String.IsNullOrEmpty(this.cboSoftWareType5.Text))
            {
                ShowMessageBox("类别不能为空");
                this.cboSoftWareType1.Focus();
                return;
            }

            if (String.IsNullOrEmpty(this.txtPath.Text))
            {
                ShowMessageBox("路径不能为空");
                this.btnSelect.Focus();
                return;
            }

            if (!System.IO.File.Exists(this.txtPath.Text))
            {
                ShowMessageBox("路径不存在");
                this.btnSelect.Focus();
                return;
            }

            ////GUID
            System.Guid gd = new Guid();
            gd = Guid.NewGuid();
            String strFileNamePrefix = gd.ToString("N");
            System.IO.FileInfo fi = new System.IO.FileInfo(this.txtPath.Text);
           
            //2009-08-10
            //String strExtension = fi.Extension;
            String strExtension = fi.Name;
            //生成文件名
            //2009-08-10

            String strFileName = strExtension;
            //String strFileName = strFileNamePrefix + strExtension;
            String strFileName1 = System.IO.Path.Combine(strFileNamePrefix, strExtension);
            ADODB.Command cmd = new ADODB.Command();
            //2009-08-10       
            //2009-08-17
            ADODB.Recordset rsCurrent = GetCurrentRs(strCurrentId);
            //D-2009-08-29
            //String strSql = "update XscSoftWare set Title='" + this.txtTitle.Text.Trim() + "',FileName='" + strFileName1 + "',SoftWare='" + this.cboSoftWareType1.Text + "',Memo='" + this.txtMemo.Text + "' where id='" + strCurrentId + "'";
            //A-2009-08-29
            //D-2009-08-29
            //String strSql = "update XscSoftWare set Title=?,FileName=?,SoftWare=?,Memo=? where id=?";
            //A-2009-08-30
            //String strSql = "update XscSoftWare set Title=?,FileName=?,SoftWare=?,Memo=?,IsSingleFile=? where id=?";//D-2009-10-10
            String strSql = "";
            if (this.chk更新文件.Checked == true)
            {
                 strSql = "update XscSoftWare set Title=?,FileName=?,Memo=?,IsSingleFile=?,OPTIME=?,OptUser=?,type1=? ,type2=? ,type3=? ,type4=? ,type5=?,AddTime=? where id=?";
            }
            else
            {
                 strSql = "update XscSoftWare set Title=?,Memo=?,IsSingleFile=?,OPTIME=?,OptUser=?,type1=? ,type2=? ,type3=? ,type4=? ,type5=?,AddTime=? where id=?";
            }           
            ADODB.Parameter pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, this.txtTitle.Text.Trim().Length, this.txtTitle.Text.Trim());
            cmd.Parameters.Append(pa);

            if (this.chk更新文件.Checked == true)
            {
                pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, strFileName1.Length, strFileName1);
                cmd.Parameters.Append(pa);
            }
            //pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, this.cboSoftWareType1.Text.Trim().Length, this.cboSoftWareType1.Text.Trim());
            //cmd.Parameters.Append(pa);

            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput,0,null);
            if (this.txtMemo.Text.Trim().Length == 0)
            {
                pa.Size = 1;
            }
            else
            {
                pa.Size = this.txtMemo.Text.Trim().Length;
            }
            pa.Value = this.txtMemo.Text.Trim();
            cmd.Parameters.Append(pa);

            //A-2009-08-30
            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, 1, null);
            pa.Precision = 2;
            pa.NumericScale = 0;
            if (this.radFile.Checked)
            {
                pa.Value = 0;
            }
            if (this.radFolder.Checked)
            {
                pa.Value = 1;
            }           
            cmd.Parameters.Append(pa);
            //A-2009-08-30

            //A-2009-10-10
            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, -1, DateTime.Now.ToString());
            cmd.Parameters.Append(pa);
            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput, strName.Length, strName);
            cmd.Parameters.Append(pa);
            //A-2009-10-10

            //类型
            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, 5, null);
            pa.Precision = 5;
            pa.NumericScale = 0;
            pa.Value = Convert.ToInt32(cboSoftWareType1.Tag);
            cmd.Parameters.Append(pa);

            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, 5, null);
            pa.Precision = 5;
            pa.NumericScale = 0;
            pa.Value = Convert.ToInt32(cboSoftWareType2.Tag);
            cmd.Parameters.Append(pa);

            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, 5, null);
            pa.Precision = 5;
            pa.NumericScale = 0;
            pa.Value = Convert.ToInt32(cboSoftWareType3.Tag);
            cmd.Parameters.Append(pa);

            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, 5, null);
            pa.Precision = 5;
            pa.NumericScale = 0;
            pa.Value = Convert.ToInt32(cboSoftWareType4.Tag);
            cmd.Parameters.Append(pa);

            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, 5, null);
            pa.Precision = 5;
            pa.NumericScale = 0;
            pa.Value = Convert.ToInt32(cboSoftWareType5.Tag);
            cmd.Parameters.Append(pa);

            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, -1, DateTime.Now.ToString());
            cmd.Parameters.Append(pa);

            pa = cmd.CreateParameter("", ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, strCurrentId.Length, strCurrentId);
            cmd.Parameters.Append(pa);

            cmd.CommandText = strSql;
            if (ct.ExcCommand(cmd)&&this.chk更新文件.Checked==true)
            {
                try
                {
                    //添加程序按钮
                    //获取基本路径
                    String strBasePath = System.Configuration.ConfigurationManager.AppSettings["SoftWarePath"];
                    //String strCurrentPath = Environment.CurrentDirectory; 2009-08-10
                    String strCurrentPath = GetCurrentDirectory();
                    String strPath = System.IO.Path.Combine(strCurrentPath, strBasePath);
                    //不存在根路径，就创建
                    if (!System.IO.Directory.Exists(strPath))
                    {
                        System.IO.Directory.CreateDirectory(strPath);
                    }
                    //查找基本目录
                    //System.Data.DataRowView dr = this.cboSoftWareType1.SelectedValue as System.Data.DataRowView;
                    //strCurrentPath = dr.Row[1].ToString();
                    //strCurrentPath = GetFolder(this.cboSoftWareType1.Tag.ToString());
                    //strPath = System.IO.Path.Combine(strPath, strCurrentPath);
                    //不存在就创建
                    strPath = System.IO.Path.Combine(strPath, strFileNamePrefix);
                    if (!System.IO.Directory.Exists(strPath))
                    {
                        System.IO.Directory.CreateDirectory(strPath);
                    }
                    //strPath = System.IO.Path.Combine(strPath, strFileName);
                    String strPath3 = strPath;
                    String strPath4 = string.Empty;

                    strPath = System.IO.Path.Combine(strPath, strFileName);
                    if (!System.IO.File.Exists(strPath))
                    {                  
                        //D-2009-08-30
                        //fi.CopyTo(strPath);                     
                        //2009-08-17 最后在删除

                        //A-2009-08-30
                        if (radFile.Checked)
                        {
                            fi.CopyTo(strPath);
                        }
                        if (radFolder.Checked)
                        {
                            CopyFoler(fi.Directory.FullName, strPath3);
                        }
                        //A-2009-08-30
                        DeleteFile(rsCurrent);
                    }
                }
                catch (Exception MyE)
                {
                    //SaveException(MyE);//D-2009-10-11
                    UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, MyE, MethodBase.GetCurrentMethod().GetType());//A-2009-10-11 
                }

            }
            strCurrentId = "";
            ShowMessageBox("修改成功");

            //A-2009-09-11
            if (iListToUpdate > -1)
            {
                this.Close();
            }
            //A-2009-09-11

            //cboSoftWareType_ItemChanged(this.cboSoftWareType.Text);
            this.RefreshData();
        }
        #endregion

        #region 得到记录集 A-2009-08-17
        //得到记录集 2009-08-17
        private ADODB.Recordset GetCurrentRs(String strid)
        {
            String strSql = " select * from XscSoftWare ";    
            strSql += "       where XscSoftWare.Id='" + strid + "'";
            ADODB.Recordset rs = ct.GetTable(strSql);
            return rs;
        }
        #endregion       

        #region 添加按钮代码
        private void btnAdd_Click(object sender, EventArgs e)
        {
            SoftWareAdd frm = new SoftWareAdd();
            //A-2009-10-10
            frm.strName = this.strName;
            frm.iType = this.iType;
            //A-2009-10-10
            frm.ShowDialog();
            if (frm.bAdd)
            {         
                //cboSoftWareType_ItemChanged(this.cboSoftWareType.Text);
                this.RefreshData();
            }

        }
        #endregion       

        #region 关闭按钮代码
        private void btnQuit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion     

        #region 得到文件路径
        public String GetFilePath(String strFileType, String strFileName)
        {
            String getFilePath="";          
            String strBasePath = System.Configuration.ConfigurationManager.AppSettings["SoftWarePath"];
            //String strCurrentPath = Environment.CurrentDirectory; 2009-08-10
            String strCurrentPath = this.GetCurrentDirectory();
            String strPath = System.IO.Path.Combine(strCurrentPath, strBasePath);         
            strPath = Path.Combine(strPath,strFileType);
            strPath = Path.Combine(strPath, strFileName);
            getFilePath = strPath;
            return getFilePath;
        }
        #endregion      

        #region 选择文件按钮代码
        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.txtPath.Text = this.openFileDialog1.FileName;
            }
        }
        #endregion

        #region 从搜索窗口到更新窗口 A-2009-09-11
        public void LoadListToUpdate(String strSql, String strSqlCount)
        {
            this.strSql = strSql;
            this.strSql1 = strSqlCount;
        }
        #endregion

        #region 刷新完数据 发行事件 添加图标列和大小列 A-2010-02-21
        private void lstView_EventPageComplete()
        {
            try
            {
                //A-2010-02-21
                if ((!_软件图标) && (!_软件大小))
                {
                    return;
                }
                //A-2010-02-21


                //A-2010-02-05追加图标列 
                if (this.lstView.MyDataView1.Columns.Count == 2)
                {

                    if (_软件图标)
                    {
                        this.lstView.MyDataView1.Columns[1].Width -= 60;
                        DataGridViewImageColumn dic = new DataGridViewImageColumn();
                        dic.Width = 55;
                        dic.HeaderText = "图标";
                        dic.Name = "图标";
                        dic.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
                        this.lstView.MyDataView1.Columns.Add(dic);
                    }

                    if (_软件大小)
                    {
                        this.lstView.MyDataView1.Columns[1].Width -= 65;
                        this.lstView.MyDataView1.Columns.Add("大小", "大小");
                    }
                }

                for (int i = 0; i < this.lstView.MyDataView1.Rows.Count; i++)
                {
                    String strSql = " select * from XscSoftWare "; //A-2009-10-11                    
                    strSql += "       where      XscSoftWare.Id='" + this.lstView.MyDataView1[0, i].Value.ToString() + "'";

                    ADODB.Recordset rs = ct.GetTable(strSql);
                    if (rs != null)
                    {
                        if (rs.EOF == false)
                        {
                            //配置路径
                            String strBasePath = System.Configuration.ConfigurationManager.AppSettings["SoftWarePath"];
                            strBasePath = System.IO.Path.Combine(this.GetCurrentDirectory(), strBasePath);
                            //strBasePath = System.IO.Path.Combine(strBasePath, rs.Fields["FolderPath"].Value.ToString());
                            strBasePath = System.IO.Path.Combine(strBasePath, rs.Fields["FileName"].Value.ToString());

                            if (System.IO.File.Exists(strBasePath))
                            {

                                System.IO.FileInfo fi = new System.IO.FileInfo(strBasePath);

                                if (_软件大小)
                                {
                                    double length = 0;
                                    foreach (System.IO.FileInfo fif in fi.Directory.GetFiles("*.*", System.IO.SearchOption.AllDirectories))
                                    {
                                        length += fif.Length;
                                    }
                                    this.lstView.MyDataView1["大小", i].Value = (length / (1024 * 1024)).ToString("#########0.00") + "MB";
                                }

                                try
                                {
                                    if (_软件图标)
                                    {
                                        Icon ic = Icon.ExtractAssociatedIcon(fi.FullName);
                                        this.lstView.MyDataView1["图标", i].Value = ic.ToBitmap() as Image;
                                    }
                                }
                                catch (Exception me)
                                {
                                    UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                }

                            }

                            rs.Close();
                        }
                    }
                    rs = null;


                }
            }
            catch (Exception me)
            {
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());//A-2009-10-11 
            }
        }
        #endregion       

        #region 重载窗体数据保存 2010-09-06
        public override void 保存窗体数据到数据库(ref DataTable dtData)
        {
            dtData.Rows.Add(new string[] { "软件类型", "Tag", cboSoftWareType.Tag.ToString() });
            dtData.Rows.Add(new string[] { "软件类型", "Text", cboSoftWareType.Text.ToString() });
        }
        public override void 存取数据库数据到窗体(DataTable dtDbData)
        {
            if (dtDbData.Rows.Count > 0)
            {
                cboSoftWareType.Tag = this.查找数据("软件类型", "Tag", "", ref dtDbData);
                cboSoftWareType.Text = this.查找数据("软件类型", "Text", "", ref dtDbData);
            }
        }
        #endregion       

        private void btnSelectType_Click(object sender, EventArgs e)
        {
            //Wys.Control.Vb.TreeTableFromBase ttf = new Wys.Control.Vb.TreeTableFromBase(this.cboSoftWareType.Tag.ToString());
            //ttf.ID = "ID";
            //ttf.ParentID = "ParentID";
            //ttf.DisplayName = "Name";
            //ttf.TableName = "XscSoftWareType";
            //ttf.Text = "请选择软件类型";
            //ttf.ShowDialog();
            //if (!ttf.Cancel)
            //{
            //    cboSoftWareType.Text = ttf.DisplayNameValue;
            //    cboSoftWareType.Tag = ttf.Result;                
            //}
            //RefreshData();
            Wys.Control.Vb.TreeTableFromBase ttf = new Wys.Control.Vb.TreeTableFromBase(cboSoftWareType.Tag.ToString());
            ttf.ID = "ID";
            ttf.ParentID = "ParentID";
            ttf.DisplayName = "Name";
            ttf.TableName = "XscBugType";
            ttf.Text = "网址类型选择";
            ttf.TypeId = 15;
            ttf.ShowDialog();
            if (!ttf.Cancel)
            {
                cboSoftWareType.Tag = ttf.Result;
                cboSoftWareType.Text = ttf.DisplayNameValue;
            }
            cboSoftWareType.Text = ct.GetParentName(cboSoftWareType.Tag.ToString(), "XscBugType", "Name", "ParentID", "ID");
            RefreshData();
        }
        public String GetFolder(String strid)
        {
            ADODB.Recordset rs = ct.GetTable("select FolderPath from XscSoftWareType where ID='" + strid + "'");
            if (rs == null)
                return "";
            if (rs.EOF)
            {
                rs.Close();
                rs = null;
                return "";
            }
            String str = rs.Fields["FolderPath"].Value.ToString();
            rs.Close();
            rs = null;
            return str;
        }

        public void LoadData(String arrListResult)
        {            
            String strSlectSql = "";
            String strCountSql = "";
            if (String.IsNullOrEmpty(arrListResult))
            {
                strSlectSql = "SELECT ID,Title as Title      FROM XscSoftWare Where 1=1 ";
                strCountSql = "SELECT count(ID) as PageCount FROM XscSoftWare Where 1=1 ";
            }
            else
            {
                //strSlectSql = "SELECT ID,Title as Title      FROM XscSoftWare where  1=1 And SoftWare in(" + arrListResult + ")";
                //strCountSql = "SELECT count(ID) as PageCount FROM XscSoftWare where  1=1 And SoftWare in(" + arrListResult + ")";

                strSlectSql = "SELECT ID,Title as Title      FROM XscSoftWare where type1 in(" + arrListResult + ") ";
                strSlectSql += " OR  type2 in(" + arrListResult + ") ";
                strSlectSql += " OR  type3 in(" + arrListResult + ") ";
                strSlectSql += " OR  type4 in(" + arrListResult + ") ";
                strSlectSql += " OR  type5 in(" + arrListResult + ") ";
                strSlectSql += " ORDER BY LastOpenTime DESC";

                strCountSql = "SELECT count(ID) as PageCount FROM XscSoftWare where type1 in(" + arrListResult + ")";
                strCountSql += " OR  type2 in(" + arrListResult + ") ";
                strCountSql += " OR  type3 in(" + arrListResult + ") ";
                strCountSql += " OR  type4 in(" + arrListResult + ") ";
                strCountSql += " OR  type5 in(" + arrListResult + ") ";
                strCountSql += " ORDER BY LastOpenTime DESC";
            }
            this.lstView.SetRsSQLITE(strSlectSql, strCountSql, ct, 1);
           
        }

        private void RefreshData()
        {
            String str = "";
            String[] strResult = GetChildIdAndSelf(cboSoftWareType.Tag.ToString());
            foreach (String strItem in strResult)
            {
                str = str + "'" + strItem + "',";
            }

            if (str == "")
            {
                str = "'" + cboSoftWareType.Text + "'";
            }
            else
            {
                if (str.EndsWith(","))
                {
                    str = str.Substring(0, str.Length - 1);
                }
            }
            FormClear();
            LoadData(str);
        }
        public void FormClear()
        {
            txtTitle.Text = "";
            cboSoftWareType1.Text = "";
            cboSoftWareType1.Tag = "-1";

            cboSoftWareType2.Text = "";
            cboSoftWareType2.Tag = "-1";

            cboSoftWareType3.Text = "";
            cboSoftWareType3.Tag = "-1";

            cboSoftWareType4.Text = "";
            cboSoftWareType4.Tag = "-1";

            cboSoftWareType5.Text = "";
            cboSoftWareType5.Tag = "-1";
            txtPath.Text = "";
            txtPath.Tag = "";
            this.radFile.Checked = true;
            txtMemo.Text = "";
        }
        private String[] GetChildIdAndSelf(String strParentId)
        {
            List<String> result = new List<string>();
            if (!result.Contains(strParentId))
            {
                result.Add(strParentId);
            }
            ADODB.Recordset rs = null;
            if (!String.IsNullOrEmpty(strParentId))
            {
                rs = ct.GetTable("select ID from XscBugType where ParentID='" + strParentId + "'");
            }
            else
            {
                rs = ct.GetTable("select ID from XscBugType where ParentID is null and type=15");
            }
            if (rs == null)
            {
                return null;
            }
            if (rs.EOF)
            {
                goto end1;
            }
            String str = "";
            String strid1 = "";
            while (!rs.EOF)
            {
                str = rs.Fields["ID"].Value.ToString();
                strid1 = rs.Fields["ID"].Value.ToString();
                if (!result.Contains(str))
                {
                    result.Add(str);
                }
                String[] resultChid = GetChildIdAndSelf(strid1);
                if (null == resultChid)
                {
                    goto end2;
                }
                foreach (String strItem in resultChid)
                {
                    if (!result.Contains(strItem))
                    {
                        result.Add(strItem);
                    }
                }
            end2:
                rs.MoveNext();
            }
        end1:
            rs.Close();
            rs = null;
            return result.ToArray();
        }

        private void myButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtPath.Text))
                {
                    return;
                }     
                UTIL.CUtil.OpenFileSetFile(txtPath.Text, ""); 
            }
            catch (Exception me)
            {
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());//A-2009-10-11 
            }
        }

        private void lstView_ItemDoubleClickRefreshData(string strId, ref bool bState)
        {
            UTIL.CUtil.OpenFile(txtPath.Text);
        }

        #region 电子书选择 2010-04-05

        public void RefreshEBook(String strFile, String IsSingle)
        {
            btn扩展.Visible = false;
            if (IsSingle != "1")
            {
                return;
            }
            if (System.IO.File.Exists(strFile))
            {
                String strExt = System.IO.Path.GetExtension(strFile).ToUpper();
                if (strExt == ".PDF" || strExt == ".PDG" || strExt == ".TXT" || strExt == ".DOC" || strExt == ".XST" || strExt == ".PPT" || strExt == ".CHM")
                {
                    String strDir = System.IO.Path.GetDirectoryName(strFile);
                    System.IO.DirectoryInfo dif = new DirectoryInfo(strDir);
                    if (dif.GetFiles().Length > 1)
                    {
                        btn扩展.Visible = true;
                    }
                }
                btn扩展.Tag = strFile;
            }
        }

        private void btn扩展_Click(object sender, EventArgs e)
        {
            if (btn扩展.Enabled)
            {
                using (SelectedForm frm = new SelectedForm())
                {
                    if (btn扩展.Tag != null)
                    {
                        frm.文件夹路径 = btn扩展.Tag.ToString();
                        frm.ShowDialog();
                    }
                }
            }
        }

        #endregion

        #region 设置单元格行数
        public override int 初始行数()
        {
            return this.lstView.PageSize;
        }
        public override void 设置窗体数据行数()
        {
            this.lstView.PageSize = Get窗体行数(lstView.PageSize);
        }
        public override bool 是否显示设置窗体数据行数()
        {
            return true;
        }
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            String strN = "";
            String strName = "";
            Button btn = sender as Button;
            if (btn == null)
            {
                return;
            }
            strName = btn.Name;
            strN = strName.Substring(strName.Length - 1, 1);

            Wys.Control.Vb.TreeTableFromBase ttf = new Wys.Control.Vb.TreeTableFromBase(类型.Controls["cboSoftWareType" + strN].Tag.ToString());
            ttf.ID = "ID";
            ttf.ParentID = "ParentID";
            ttf.DisplayName = "Name";
            ttf.TableName = "XscBugType";
            ttf.Text = "请选择软件类型";
            ttf.TypeId = 15;
            ttf.ShowDialog();
            if (!ttf.Cancel)
            {
                if (Convert.ToInt32(strN) > 1)
                {
                    for (int index = 1; index < Convert.ToInt32(strN); index++)
                    {
                        if (Convert.ToInt32(类型.Controls["cboSoftWareType" + index].Tag) == Convert.ToInt32(ttf.Result))
                        {
                            ShowMessageBox("类型不能重复");
                            return;
                        }
                    }
                }
                类型.Controls["cboSoftWareType" + strN].Text = ttf.DisplayNameValue;
                类型.Controls["cboSoftWareType" + strN].Tag = ttf.Result;
            }
            类型.Controls["cboSoftWareType" + strN].Text = ct.GetParentName(类型.Controls["cboSoftWareType" + strN].Tag.ToString(), "XscBugType", "Name", "ParentID", "ID");
        }

        private void cboSoftWareType1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (tb != null)
            {
                tb.Text = "";
                tb.Tag = "-1";
            }
        }
    }
}
